home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / game / wins1726.zip / WINFRACT.C < prev    next >
C/C++ Source or Header  |  1992-06-15  |  83KB  |  2,232 lines

  1. /****************************************************************************
  2.  
  3.  
  4.     PROGRAM: winfract.c
  5.  
  6.     PURPOSE: Windows-specific main-driver code for Fractint for Windows
  7.              (look in MAINFRAC.C for the non-windows-specific code)
  8.  
  9.     Copyright (C) 1990 The Stone Soup Group.  Fractint for Windows 
  10.     may be freely copied and distributed, but may not be sold.
  11.     
  12.     We are, of course, copyrighting the code we wrote to implement
  13.     Fractint-for-Windows, and not the routines we lifted directly
  14.     or indirectly from Microsoft's Windows 3.0 Software Development Kit.
  15.  
  16. ****************************************************************************/
  17.  
  18. #include "windows.h"
  19. #include "winfract.h"
  20. #include "mathtool.h"
  21. #include "fractype.h"
  22. #include "fractint.h"
  23. #include "select.h"
  24. #include <math.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <search.h>
  28. #include <string.h>
  29. #include <time.h>
  30. #include "profile.h"
  31.  
  32. #ifndef WINVER
  33. #define WINVER 0x0300        /* assume Windows 3.0 SDK if not found */
  34. #endif
  35.  
  36. unsigned int windows_version;        /* 0x0300 = Win 3.0, 0x030A = 3.1 */
  37.  
  38. extern LPSTR win_lpCmdLine;
  39.  
  40. HANDLE hInst;
  41.  
  42. HANDLE hAccTable;                        /* handle to accelerator table */
  43. extern BOOL ZoomBarOpen;
  44. int ZoomMode;
  45.  
  46. HWND hMainWnd, hwnd;                     /* handle to main window */
  47. HWND hWndCopy;                 /* Copy of hWnd */
  48.  
  49. char winfract_title_text[41];        /* Winfract title-bar text */
  50.  
  51. #define PALETTESIZE 256               /* dull-normal VGA                    */
  52. HANDLE hpal;                          /* palette handle                     */
  53. PAINTSTRUCT ps;                       /* paint structure                    */
  54. HDC hDC;                              /* handle to device context           */
  55. HDC hMemoryDC;                        /* handle to memory device context    */
  56. BITMAP Bitmap;                        /* bitmap structure                   */
  57. extern time_t last_time;
  58. unsigned IconWidth, IconHeight, IconSize;
  59. HANDLE hIconBitmap;
  60.  
  61. HANDLE  hPal;          /* Handle to the application's logical palette  */
  62. HANDLE  hLogPal;       /* Temporary Handle */
  63. LPLOGPALETTE pLogPal;  /* pointer to tha application's logical palette */
  64. int     iNumColors;    /* Number of colors supported by device           */
  65. int     iRasterCaps;   /* Raster capabilities                           */
  66. int     iPalSize;      /* Size of Physical palette                       */
  67.  
  68. BOOL    win_systempaletteused = FALSE;    /* flag system palette set */
  69. extern int win_syscolorindex[21];
  70. extern DWORD win_syscolorold[21];
  71. extern DWORD win_syscolornew[21];
  72.  
  73. /* MCP 6-16-91 */
  74. extern int pixelshift_per_byte;
  75. extern long pixels_per_bytem1;        /* pixels / byte - 1 (for ANDing) */
  76. extern unsigned char win_andmask[8];
  77. extern unsigned char win_notmask[8];
  78. extern unsigned char win_bitshift[8];
  79.  
  80. extern int CoordBoxOpen;
  81. extern HWND hCoordBox;
  82. extern int TrackingZoom, Zooming, ReSizing;
  83.  
  84. #define EXE_NAME_MAX_SIZE  128
  85.  
  86. BOOL       bHelp = FALSE;      /* Help mode flag; TRUE = "ON"*/
  87. HCURSOR    hHelpCursor;        /* Cursor displayed when in help mode*/
  88. char       szHelpFileName[EXE_NAME_MAX_SIZE+1];    /* Help file name*/
  89.  
  90. void MakeHelpPathName(char*);  /* Function deriving help file path */
  91.  
  92. unsigned char far win_dacbox[256][3];
  93. extern unsigned char dacbox[256][3], olddacbox[256][3];
  94. extern int colorpreloaded;
  95. extern int  colorstate;
  96.  
  97. int win_fastupdate;                   /* 0 for "normal" fast screen updates */
  98. extern int show_orbit;
  99.  
  100. int max_colors;
  101.  
  102. BOOL bTrack = FALSE;                  /* TRUE if user is selecting a region */
  103. BOOL bMove  = FALSE;
  104. BOOL bMoving = FALSE;
  105. BOOL zoomflag = FALSE;                /* TRUE is a zoom-box selected */
  106. extern POINT DragPoint;
  107. RECT Rect;
  108.  
  109. int Shape = SL_ZOOM;            /* shape to use for the selection rectangle */
  110.  
  111. /* pointers to various dialog-box routines */
  112. FARPROC lpProcAbout;
  113. FARPROC lpOpenDlg;
  114. FARPROC lpSelectFractal;
  115. FARPROC lpSelectFracParams;
  116. FARPROC lpSelectImage;
  117. FARPROC lpSelectDoodads;
  118. FARPROC lpSelectExtended;
  119. FARPROC lpSelectSavePar;
  120. FARPROC lpSelectCycle;
  121. FARPROC lpSaveAsDlg;
  122. FARPROC lpProcStatus;
  123. FARPROC lpSelect3D;
  124. FARPROC lpSelect3DPlanar;
  125. FARPROC lpSelect3DSpherical;
  126. FARPROC lpSelectIFS3D;
  127. FARPROC lpSelectFunnyGlasses;
  128. FARPROC lpSelectLightSource;
  129. FARPROC lpSelectStarfield;
  130.  
  131. extern int FileFormat;
  132. extern unsigned char readname[], FileName[], FormFileName[];
  133. extern unsigned char FullPathName[], DefPath[];
  134. extern unsigned char LFileName[], LName[];
  135. extern unsigned char DialogTitle[], DefSpec[], DefExt[];
  136.  
  137. HBITMAP hBitmap, oldBitmap, oldoldbitmap;              /* working bitmaps */
  138.  
  139. HANDLE hDibInfo;        /* handle to the Device-independent bitmap */
  140. LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  141. HANDLE hpixels;            /* handle to the DIB pixels */
  142. unsigned char huge *pixels;    /* the device-independent bitmap  pixels */
  143. extern int bytes_per_pixelline;    /* pixels/line / pixels/byte */
  144. extern long win_bitmapsize;     /* size of the DIB in bytes */
  145. extern    int    resave_flag;    /* resaving after a timed save */
  146. extern    char overwrite;     /* overwrite on/off */
  147.  
  148. HANDLE hClipboard1, hClipboard2, hClipboard3; /* handles to clipboard info */
  149. LPSTR lpClipboard1, lpClipboard2;            /* pointers to clipboard info */
  150.  
  151. int last_written_y = -2;        /* last line written */
  152. int screen_to_be_cleared = 1;    /* flag that the screen is to be cleared */
  153. int time_to_act = 0;        /* time to take some sort of action? */
  154. int time_to_restart = 0;        /* time to restart?  */
  155. int time_to_reinit = 0;         /* time to reinitialize?  */
  156. int time_to_resume = 0;        /* time to resume? */
  157. int time_to_quit = 0;           /* time to quit? */
  158. int time_to_save = 0;        /* time to save the file? */
  159. int time_to_print = 0;        /* time to print the file? */
  160. int time_to_load = 0;        /* time to load a new file? */
  161. int time_to_cycle = 0;          /* time to begin color-cycling? */
  162. int time_to_starfield = 0;      /* time to make a starfield? */
  163. int time_to_orbit = 0;          /* time to activate orbits? */
  164.  
  165. int win_3dspherical = 0;          /* spherical 3D? */
  166. int win_display3d, win_overlay3d; /* 3D flags */
  167. extern    int    init3d[20];    /* '3d=nn/nn/nn/...' values */
  168. extern    int RAY;
  169.  
  170. extern int win_cycledir, win_cyclerand, win_cycledelay;
  171.  
  172. extern int calc_status;
  173.  
  174. int xdots, ydots, colors, maxiter;
  175. int ytop, ybottom, xleft, xright;
  176. int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  177. int win_xdots, win_ydots;
  178. extern int fractype;
  179. extern double param[4];
  180. extern double xxmin, xxmax, yymin, yymax, xx3rd, yy3rd;
  181. double jxxmin, jxxmax, jyymin, jyymax, jxx3rd, jyy3rd;
  182. extern int frommandel, bitshift, biomorph;
  183. extern int maxit;
  184.  
  185. extern char str[255];
  186.  
  187. int cpu, fpu;            /* cpu, fpu flags */
  188.  
  189. extern int win_release;
  190.  
  191. char *win_choices[100];
  192. int win_numchoices, win_choicemade;
  193.  
  194. extern int onthelist[];
  195. extern int CountFractalList;
  196. extern int CurrentFractal;
  197. int MaxFormNameChoices = 80;
  198. char FormNameChoices[80][25];
  199. extern char FormName[30];
  200. extern char    IFSFileName[];    /* IFS code file */
  201. extern char    IFSName[];        /* IFS code item */
  202. double far *temp_array;
  203. HANDLE htemp_array;
  204.  
  205. HANDLE hSaveCursor;             /* the original cursor value */
  206. HANDLE hHourGlass;              /* the hourglass cursor value */
  207.  
  208. BOOL winfract_menustyle = FALSE;/* Menu style:
  209.                    FALSE = Winfract-style,
  210.                    TRUE  = Fractint-style */
  211.  
  212. /* far strings (near space is precious) */
  213. char far winfract_msg01[] = "Fractint For Windows";
  214. char far winfract_msg02[] = "WinFracMenu";
  215. char far winfract_msg03[] = "FractintForWindowsV0010";
  216. char far winfract_msg04[] = "WinfractAcc";
  217. char far winfract_msg96[] = "I'm sorry, but color-cycling \nrequires a palette-based\nvideo driver";
  218. char far winfract_msg97[] = "There isn't enough available\nmemory to run Winfract";
  219. char far winfract_msg98[] =  "This program requires Standard\nor 386-Enhanced Mode";
  220. char far winfract_msg99[] = "Not Enough Free Memory to Copy to the Clipboard";
  221.  
  222. /****************************************************************************
  223.  
  224.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  225.  
  226.     PURPOSE: calls initialization function, processes message loop
  227.  
  228. ****************************************************************************/
  229.  
  230. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  231. HANDLE hInstance;
  232. HANDLE hPrevInstance;
  233. LPSTR lpCmdLine;
  234. int nCmdShow;
  235. {
  236.     win_lpCmdLine = lpCmdLine;
  237.  
  238.     if (!hPrevInstance)
  239.         if (!InitApplication(hInstance))
  240.             return (FALSE);
  241.  
  242.     if (!InitInstance(hInstance, nCmdShow))
  243.         return (FALSE);
  244.  
  245.     fractint_main();            /* fire up the main Fractint code */
  246.     if(htemp_array) {
  247.         GlobalUnlock(htemp_array);
  248.         GlobalFree(htemp_array);
  249.     }
  250.     
  251.     wintext_destroy();        /* destroy the text window */
  252.  
  253.     DestroyWindow(hWndCopy);    /* stop everything when it returns */
  254.  
  255.     return(0);                  /* we done when 'fractint_main' returns */
  256. }
  257.  
  258. /****************************************************************************
  259.  
  260.     FUNCTION: InitApplication(HANDLE)
  261.  
  262.     PURPOSE: Initializes window data and registers window class
  263.  
  264. ****************************************************************************/
  265.  
  266. BOOL InitApplication(hInstance)
  267. HANDLE hInstance;
  268. {
  269.     WNDCLASS  wc;
  270.  
  271.     wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  272.     wc.lpfnWndProc = MainWndProc;
  273.     wc.cbClsExtra = 0;
  274.     wc.cbWndExtra = 0;
  275.     wc.hInstance = hInstance;
  276.     wc.hIcon = NULL;
  277.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  278.     wc.hbrBackground = GetStockObject(BLACK_BRUSH);
  279.     wc.lpszMenuName =  winfract_msg02;
  280.     wc.lpszClassName = winfract_msg03;
  281.  
  282.     return(RegisterClass(&wc) && RegisterMathWindows(hInstance));
  283. }
  284.  
  285.  
  286. /****************************************************************************
  287.  
  288.     FUNCTION:  InitInstance(HANDLE, int)
  289.  
  290.     PURPOSE:  Saves instance handle and creates main window
  291.  
  292. ****************************************************************************/
  293. BOOL InitInstance(hInstance, nCmdShow)
  294.     HANDLE          hInstance;
  295.     int             nCmdShow;
  296. {
  297.     DWORD WinFlags;
  298.     unsigned int version, i;
  299.     int iLoop, jLoop;
  300.     DWORD ThisColor;
  301.  
  302.     float temp;
  303.  
  304.     /* so, what kind of a computer are we on, anyway? */
  305.     WinFlags = GetWinFlags();
  306.     cpu = 88;                             /* determine the CPU type */
  307.     if (WinFlags & WF_CPU186) cpu = 186;
  308.     if (WinFlags & WF_CPU286) cpu = 286;
  309.     if (WinFlags & WF_CPU386) cpu = 386;
  310.     if (WinFlags & WF_CPU486) cpu = 386;
  311.     fpu = 0;                              /* determine the FPU type */
  312.     if (WinFlags & WF_80x87)  fpu = 87;
  313.     if (fpu && (cpu == 386))  fpu = 387;
  314.  
  315.     version = LOWORD(GetVersion());    /* which version of Windows is it? */
  316.     windows_version = ((LOBYTE(version) << 8) | HIBYTE(version));
  317.  
  318.     hInst = hInstance;
  319.  
  320.     hAccTable = LoadAccelerators(hInst, winfract_msg04);
  321.  
  322.     temp = win_release / 100.0;
  323.     sprintf(winfract_title_text,"Fractint for Windows - Vers %5.2f", temp);
  324.  
  325.     hMainWnd = hwnd = CreateWindow(
  326.         winfract_msg03,
  327.         winfract_title_text,
  328.         WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
  329.         140, 100,  /* initial locn instead of CW_USEDEFAULT, CW_USEDEFAULT, */
  330.         360, 280,  /* initial size instead of CW_USEDEFAULT, CW_USEDEFAULT, */
  331.         NULL,
  332.         NULL,
  333.         hInstance,
  334.         NULL
  335.     );
  336.  
  337.     if (!hwnd) {  /* ?? can't create the initial window! */
  338.         return (FALSE);
  339.         }
  340.  
  341.     wintext_initialize(
  342.         (HANDLE) hInstance,
  343.         (HWND) hwnd,
  344.         (LPSTR) winfract_title_text);
  345.  
  346.     /* This program doesn't run in "real" mode, so shut down right
  347.        now to keep from mucking up Windows */
  348.     if (!((WinFlags & WF_STANDARD) || (WinFlags & WF_ENHANCED))) {
  349.         MessageBox (
  350.             GetFocus(),
  351.             winfract_msg98,
  352.             winfract_msg01,
  353.             MB_ICONSTOP | MB_OK);
  354.         return(FALSE);
  355.         }
  356.     
  357.     win_xdots = xdots;
  358.     win_ydots = ydots;
  359.     maxiter = 150;                   /* and a few iterations */
  360.     xposition = yposition = 0;       /* dummy up a few pointers */
  361.     xpagesize = ypagesize = 2000;
  362.     set_win_offset();
  363.  
  364.     /* obtain an hourglass cursor */
  365.     hHourGlass  = LoadCursor(NULL, IDC_WAIT);
  366.     hSaveCursor = LoadCursor(NULL, IDC_ARROW);
  367.  
  368.     SizeWindow(hwnd);
  369.     ShowWindow(hwnd, nCmdShow);
  370.     UpdateWindow(hwnd);
  371.  
  372.     /* let's ensure that we have at lease 40K of free memory */
  373.     {
  374.     HANDLE temphandle;
  375.     if (!(temphandle = GlobalAlloc(GMEM_FIXED,40000L)) ||
  376.         !(htemp_array = GlobalAlloc(GMEM_FIXED, sizeof(double) * 8001))) {
  377.         MessageBox (
  378.             GetFocus(),
  379.             winfract_msg97,
  380.             winfract_msg01,
  381.             MB_ICONSTOP | MB_OK);
  382.         return(FALSE);
  383.         }
  384.         GlobalLock(temphandle);
  385.         GlobalUnlock(temphandle);
  386.         GlobalFree(temphandle);
  387.         temp_array = (double far *)GlobalLock(htemp_array);
  388.     }
  389.  
  390.    MakeHelpPathName(szHelpFileName);
  391.  
  392.     /* so, what kind of a display are we using, anyway? */
  393.     hDC = GetDC(NULL);
  394.     iPalSize    = GetDeviceCaps (hDC, SIZEPALETTE);
  395.     iRasterCaps = GetDeviceCaps (hDC, RASTERCAPS);
  396.     iRasterCaps = (iRasterCaps & RC_PALETTE) ? TRUE : FALSE;
  397.     if (iRasterCaps)
  398.        iNumColors = GetDeviceCaps(hDC, SIZEPALETTE);
  399.     else
  400.        iNumColors = GetDeviceCaps(hDC, NUMCOLORS);
  401.     ReleaseDC(NULL,hDC);
  402.  
  403.     /* fudges for oddball stuff (is there any?) */
  404.     /* also, note that "true color" devices return -1 for NUMCOLORS */
  405.     colors = iNumColors;
  406.     if (colors < 2 || colors > 16) colors = 256;
  407.     if (colors > 2 && colors < 16) colors = 16;
  408.     /* adjust for Windows' 20 reserved palettes in 256-color mode */
  409.     max_colors = 256;
  410.     if (colors == 256  && iNumColors >= 0) max_colors = 236;
  411.  
  412.      /* Allocate enough memory for a logical palette with
  413.       * PALETTESIZE entries and set the size and version fields
  414.       * of the logical palette structure.
  415.       */
  416.      if (!(hLogPal = GlobalAlloc (GMEM_FIXED,
  417.         (sizeof (LOGPALETTE) +
  418.         (sizeof (PALETTEENTRY) * (PALETTESIZE)))))) {
  419.         MessageBox (
  420.             GetFocus(),
  421.             winfract_msg97,
  422.             winfract_msg01,
  423.             MB_ICONSTOP | MB_OK);
  424.         return(FALSE);
  425.           }
  426.     pLogPal = (LPLOGPALETTE)GlobalLock(hLogPal); 
  427.     pLogPal->palVersion    = 0x300;
  428.     pLogPal->palNumEntries = PALETTESIZE;
  429.     /* fill in intensities for all palette entry colors */
  430.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++) {
  431.         pLogPal->palPalEntry[iLoop].peRed   = iLoop;
  432.         pLogPal->palPalEntry[iLoop].peGreen = 0;
  433.         pLogPal->palPalEntry[iLoop].peBlue  = 0;
  434.         pLogPal->palPalEntry[iLoop].peFlags = PC_EXPLICIT;
  435.         }
  436.     /* flip the ugly red color #1 with the pretty blue color #4 */
  437.     if (iNumColors < 0 || iNumColors > 4) {
  438.         pLogPal->palPalEntry[1].peRed = 4;
  439.         pLogPal->palPalEntry[4].peRed = 1;
  440.         }
  441.     /*  create a logical color palette according the information
  442.         in the LOGPALETTE structure. */
  443.     hDC = GetDC(GetFocus());
  444.     SetMapMode(hDC,MM_TEXT);
  445.     hPal = CreatePalette ((LPLOGPALETTE) pLogPal) ;
  446.     /* attempt to default to a reasonable Windows palette map */
  447.     ReleaseDC(GetFocus(),hDC);
  448.     if (ValidateLuts("defaultw.map") == 0)
  449.             spindac(0,1);
  450.     /* get the "real" colors */
  451.     hDC = GetDC(GetFocus());
  452.     SelectPalette (hDC, hPal, 1);
  453.     RealizePalette(hDC);
  454.     jLoop = iNumColors;
  455.     if (jLoop < 0) jLoop = -1;
  456.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++){
  457.         if (++jLoop >= iNumColors)
  458.             if (iNumColors > 0)
  459.                 jLoop = 0;
  460.         ThisColor = GetNearestColor (hDC, PALETTEINDEX (jLoop) );
  461.         win_dacbox[iLoop][0] = dacbox[iLoop][0] =
  462.             ((BYTE)GetRValue (ThisColor)) >> 2;
  463.         win_dacbox[iLoop][1] = dacbox[iLoop][1] =
  464.             ((BYTE)GetGValue (ThisColor)) >> 2;
  465.         win_dacbox[iLoop][2] = dacbox[iLoop][2] =
  466.             ((BYTE)GetBValue (ThisColor)) >> 2;
  467.         }
  468.     ReleaseDC(GetFocus(),hDC);
  469.  
  470.     if (dacbox[0][0] == 0 && dacbox[0][1] == 0 && dacbox[0][2] == 0 && 
  471.         dacbox[1][0] == 0 && dacbox[1][1] == 0 && dacbox[1][2] == 0) {
  472.         /* huh?? We have a black-on-black palette??? */
  473.         if (ValidateLuts("defaultw.map") == 0) {
  474.             for (iLoop = 0; iLoop < PALETTESIZE; iLoop++)
  475.                for (jLoop = 0; jLoop < 3; jLoop++)
  476.                    win_dacbox[iLoop][jLoop] = dacbox[iLoop][jLoop];
  477.             spindac(0,1);
  478.             }
  479.         }
  480.  
  481.     /* allocate a device-independent bitmap header */
  482.     if (!(hDibInfo = GlobalAlloc(GMEM_FIXED,
  483.         sizeof(BITMAPINFOHEADER)+256*sizeof(PALETTEENTRY)))) {
  484.         MessageBox (
  485.             GetFocus(),
  486.             winfract_msg97,
  487.             winfract_msg01,
  488.             MB_ICONSTOP | MB_OK);
  489.         return(FALSE);
  490.         }
  491.     pDibInfo = (LPBITMAPINFO)GlobalLock(hDibInfo);
  492.     /* fill in the header */
  493.     pDibInfo->bmiHeader.biSize  = (long)sizeof(BITMAPINFOHEADER);
  494.     pDibInfo->bmiHeader.biWidth  = win_xdots;
  495.     pDibInfo->bmiHeader.biHeight = win_ydots;
  496.     pDibInfo->bmiHeader.biSizeImage = (DWORD)win_xdots * win_ydots;
  497.     pDibInfo->bmiHeader.biPlanes = 1;
  498.     pDibInfo->bmiHeader.biBitCount = 8;
  499.     pDibInfo->bmiHeader.biCompression = BI_RGB;
  500.     pDibInfo->bmiHeader.biXPelsPerMeter = 0L;
  501.     pDibInfo->bmiHeader.biYPelsPerMeter = 0L;
  502.     pDibInfo->bmiHeader.biClrUsed = 0L;
  503.     pDibInfo->bmiHeader.biClrImportant = 0L;
  504.     default_dib_palette();
  505.  
  506.     IconWidth = GetSystemMetrics(SM_CXICON);
  507.     IconHeight = GetSystemMetrics(SM_CYICON);
  508.     IconSize = (IconWidth * IconHeight) >> pixelshift_per_byte;
  509.     hIconBitmap = GlobalAlloc(GMEM_MOVEABLE, IconSize);
  510.  
  511.     /* initialize our delay counter */
  512.     CalibrateDelay();
  513.     win_cycledelay = 15;
  514.  
  515.     /* allocate and lock a pixel array for the initial bitmap */
  516.     hpixels = (HANDLE) 0;
  517.     pixels = (char huge *) NULL;
  518.     if (hIconBitmap && clear_screen(0))
  519.         return(TRUE);
  520.  
  521.     MessageBox (
  522.         GetFocus(),
  523.         winfract_msg97,
  524.         winfract_msg01,
  525.          MB_ICONSTOP | MB_OK);
  526.  
  527.     return (FALSE);
  528.  
  529. }
  530.  
  531. /****************************************************************************
  532.  
  533.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  534.  
  535.     PURPOSE:  Processes messages
  536.  
  537. ****************************************************************************/
  538.  
  539. void lmemcpy(  char huge *to,  char huge *from, long len)
  540. {
  541. long i;
  542.  
  543. for (i = 0; i < len; i++)
  544.   to[i] = from[i];
  545. }
  546.  
  547. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  548. HWND hWnd;                /* handle to main window */
  549. unsigned message;
  550. WORD wParam;
  551. LONG lParam;
  552. {
  553.  
  554.     RECT tempRect;
  555.     HMENU hMenu;
  556.  
  557.     int Return;
  558.     int i, fchoice;
  559.     extern char FractintMenusStr[];
  560.     extern char FractintPixelsStr[];
  561.  
  562.     switch (message) {
  563.  
  564.         case WM_INITMENU:
  565.            if (!iRasterCaps || iNumColors < 16) {
  566.                EnableMenuItem(GetMenu(hWnd), IDM_CYCLE, MF_DISABLED | MF_GRAYED);
  567.                }
  568.            hMenu = GetMenu(hWnd);
  569.            if (winfract_menustyle) {
  570.                CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_CHECKED);
  571.                CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_UNCHECKED);
  572.                }
  573.            else {
  574.                CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_UNCHECKED);
  575.                CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_CHECKED);
  576.                }
  577.            if (win_fastupdate)
  578.                CheckMenuItem(hMenu, IDM_PIXELS, MF_CHECKED);
  579.            else
  580.                CheckMenuItem(hMenu, IDM_PIXELS, MF_UNCHECKED);
  581.            hWndCopy = hWnd;
  582.            return (TRUE);
  583.  
  584.         case WM_LBUTTONDBLCLK:
  585.             if(Zooming) {
  586.                win_savedac();
  587.                ExecuteZoom();
  588.                }
  589.             if (bMove) {
  590.                DragPoint = MAKEPOINT(lParam);
  591.         ExecZoom:
  592.                /* End the selection */
  593.                EndSelection(DragPoint, &Rect);
  594.                ClearSelection(hWnd, &Rect, Shape);
  595.  
  596.                if(PtInRect(&Rect, DragPoint)) {
  597.                   if (abs(Rect.bottom - Rect.top ) > 5 &&
  598.                       abs(Rect.right  - Rect.left) > 5) {
  599.                         double xd, yd, z;
  600.                         extern POINT Center, ZoomDim;
  601.                         extern double delxx, delyy;
  602.         
  603.             z = (double)(ZoomDim.x << 1) / xdots;
  604.             if(ZoomMode == IDM_ZOOMOUT) {
  605.                 z = 1.0 / z;
  606.                 xd = (xxmin + xxmax) / 2 - (delxx * z * (Center.x + win_xoffset - (xdots/2)));
  607.                 yd = (yymin + yymax) / 2 + (delxx * z * (Center.y + win_yoffset - (ydots/2)));
  608.                 }
  609.             else {
  610.                 xd = xxmin + (delxx * (Center.x + win_xoffset));  /* BDT 11/6/91 */
  611.                 yd = yymax - (delyy * (Center.y + win_yoffset));  /* BDT 11/6/91 */
  612.                 }
  613.             xxmin = xd - (delxx * z * (xdots / 2));
  614.             xxmax = xd + (delxx * z * (xdots / 2));
  615.             yymin = yd - (delyy * z * (ydots / 2));
  616.             yymax = yd + (delyy * z * (ydots / 2));
  617.             }
  618.  
  619.                       zoomflag = TRUE;
  620.                       win_savedac();
  621.                       time_to_restart = 1;
  622.                       time_to_cycle = 0;
  623.                       calc_status = 0;
  624.                   }
  625.  
  626.                   bMove = FALSE;
  627.                   bMoving = FALSE;
  628.                   bTrack = FALSE;
  629.                }
  630.  
  631.             break;
  632.  
  633.         case WM_LBUTTONDOWN:           /* message: left mouse button pressed */
  634.  
  635.             /* Start selection of region */
  636.  
  637.             if(bMove)
  638.             {
  639.                DragPoint = MAKEPOINT(lParam);
  640.                bMoving   = PtInRect(&Rect, DragPoint);
  641.                if(bMoving)
  642.                   SetCapture(hWnd);
  643.             }
  644.             else if(Zooming)
  645.                StartZoomTracking(lParam);
  646.             else if(ZoomMode == IDM_ZOOMIN || ZoomMode == IDM_ZOOMOUT)
  647.             {
  648.                bTrack = TRUE;
  649.                bMoving = FALSE;
  650.                bMove = FALSE;
  651.                SetRectEmpty(&Rect);
  652.                StartSelection(hWnd, MAKEPOINT(lParam), &Rect,
  653.                    (wParam & MK_SHIFT) ? (SL_EXTEND | Shape) : Shape);
  654.             }
  655.             break;
  656.  
  657.         case WM_MOUSEMOVE:                        /* message: mouse movement */
  658.  
  659.             /* Update the selection region */
  660.  
  661.             if (bTrack || bMoving)
  662.                 UpdateSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape);
  663.             if(CoordBoxOpen)
  664.                 UpdateCoordBox(lParam);
  665.             if(TrackingZoom)
  666.                TrackZoom(lParam);
  667.             break;
  668.  
  669.         case WM_LBUTTONUP:            /* message: left mouse button released */
  670.  
  671.             if(bTrack)
  672.             {
  673.                bTrack = FALSE;
  674.                bMove = TRUE;
  675.                ReleaseCapture();
  676.                if (abs(Rect.bottom - Rect.top ) <= 5 ||
  677.                    abs(Rect.right  - Rect.left) <= 5) {
  678.                    /* Zoom Box is too small - kill it off */
  679.                    ClearSelection(hWnd, &Rect, Shape);
  680.                    bMove = bMoving = bTrack = FALSE;
  681.                    }
  682.             }
  683.             else if(bMoving)
  684.             {
  685.                bMoving = FALSE;
  686.                ReleaseCapture();
  687.             }
  688.             else if(TrackingZoom)
  689.                EndZoom(lParam);
  690.             break;
  691.  
  692.         case WM_RBUTTONUP:
  693.             {
  694.             int xx, yy;
  695.             win_kill_all_zooming();
  696.             xx = LOWORD(lParam);
  697.             yy = HIWORD(lParam);
  698.             xx += win_xoffset;
  699.             yy += win_yoffset;
  700.             if (xx >= xdots || yy >= ydots) 
  701.                 break;
  702.             if (fractalspecific[fractype].tojulia != NOFRACTAL
  703.                 && param[0] == 0.0 && param[1] == 0.0) {
  704.                 /* switch to corresponding Julia set */
  705.                 fractype = fractalspecific[fractype].tojulia;
  706.                 param[0] = xxmin + (xxmax - xxmin) * xx / xdots;
  707.                 param[1] = yymax - (yymax - yymin) * yy / ydots;
  708.                 jxxmin = xxmin; jxxmax = xxmax;
  709.                 jyymax = yymax; jyymin = yymin;
  710.                 jxx3rd = xx3rd; jyy3rd = yy3rd;
  711.                 frommandel = 1;
  712.                 xxmin = fractalspecific[fractype].xmin;
  713.                 xxmax = fractalspecific[fractype].xmax;
  714.                 yymin = fractalspecific[fractype].ymin;
  715.                 yymax = fractalspecific[fractype].ymax;
  716.                 xx3rd = xxmin;
  717.                 yy3rd = yymin;
  718.                 if(biomorph != -1 && bitshift != 29) {
  719.                    xxmin *= 3.0;
  720.                    xxmax *= 3.0;
  721.                    yymin *= 3.0;
  722.                    yymax *= 3.0;
  723.                    xx3rd *= 3.0;
  724.                    yy3rd *= 3.0;
  725.                    }
  726.                 calc_status = 0;
  727.                 }
  728.             else if (fractalspecific[fractype].tomandel != NOFRACTAL) {
  729.                 /* switch to corresponding Mandel set */
  730.                 fractype = fractalspecific[fractype].tomandel;
  731.                 if (frommandel) {
  732.                     xxmin = jxxmin;  xxmax = jxxmax;
  733.                     yymin = jyymin;  yymax = jyymax;
  734.                     xx3rd = jxx3rd;  yy3rd = jyy3rd;
  735.                     }
  736.                 else {
  737.                     double ccreal,ccimag;
  738.                     ccreal = (fractalspecific[fractype].xmax - fractalspecific[fractype].xmin) / 2;
  739.                     ccimag = (fractalspecific[fractype].ymax - fractalspecific[fractype].ymin) / 2;
  740.                     xxmin = xx3rd = param[0] - ccreal;
  741.                     xxmax = param[0] + ccreal;
  742.                     yymin = yy3rd = param[1] - ccimag;
  743.                     yymax = param[1] + ccimag;
  744.                     }
  745.                 frommandel = 0;
  746.                 param[0] = 0;
  747.                 param[1] = 0;
  748.                 calc_status = 0;
  749.                 }
  750.             else {
  751.                 buzzer(2); /* can't switch */
  752.                 break;
  753.                 }
  754.  
  755.             ytop    = 0;
  756.             ybottom = ydots-1;
  757.             xleft   = 0;
  758.             xright  = xdots-1;
  759.  
  760.             time_to_restart  = 1;
  761.             time_to_cycle = 0;
  762.             calc_status = 0;
  763.             }
  764.             break;
  765.  
  766.         case WM_CREATE:
  767.  
  768.             /* the scroll bars are hard-coded to 100 possible values */
  769.             xposition = yposition = 0;      /* initial scroll-bar positions */
  770.             SetScrollRange(hWnd,SB_HORZ,0,100,FALSE);
  771.             SetScrollRange(hWnd,SB_VERT,0,100,FALSE);
  772.             SetScrollPos(hWnd,SB_HORZ,xposition,TRUE);
  773.             SetScrollPos(hWnd,SB_VERT,yposition,TRUE);
  774.             InitializeParameters(hWnd);
  775.             break;
  776.  
  777.         case WM_SIZE:
  778.             win_kill_all_zooming();
  779.             xpagesize = LOWORD(lParam);        /* remember the window size */
  780.             ypagesize = HIWORD(lParam);
  781.         set_win_offset();
  782.             if(!ReSizing && !IsIconic(hWnd))
  783.            ReSizeWindow(hWnd);
  784.             break;
  785.  
  786.         case WM_MOVE:
  787.             SaveWindowPosition(hWnd, WinfractPosStr);
  788.             break;
  789.  
  790.         case WM_HSCROLL:
  791.             win_kill_all_zooming();
  792.             switch (wParam) {
  793.                case SB_LINEDOWN:       xposition += 1; break;
  794.                case SB_LINEUP:         xposition -= 1; break;
  795.                case SB_PAGEDOWN:       xposition += 10; break;
  796.                case SB_PAGEUP:         xposition -= 10; break;
  797.                case SB_THUMBPOSITION:  xposition = LOWORD(lParam);
  798.                default:                break;
  799.                }
  800.             if (xposition > 100) xposition = 100;
  801.             if (xposition <     0) xposition = 0;
  802.             if (xposition != GetScrollPos(hWnd,SB_HORZ)) {
  803.                SetScrollPos(hWnd,SB_HORZ,xposition,TRUE);
  804.                InvalidateRect(hWnd,NULL,TRUE);
  805.                }
  806.             set_win_offset();
  807.            break;
  808.         case WM_VSCROLL:
  809.             win_kill_all_zooming();
  810.             switch (wParam) {
  811.                case SB_LINEDOWN:       yposition += 1; break;
  812.                case SB_LINEUP:         yposition -= 1; break;
  813.                case SB_PAGEDOWN:       yposition += 10; break;
  814.                case SB_PAGEUP:         yposition -= 10; break;
  815.                case SB_THUMBPOSITION:  yposition = LOWORD(lParam);
  816.                default:                break;
  817.                }
  818.             if (yposition > 100) yposition = 100;
  819.             if (yposition <     0) yposition = 0;
  820.             if (yposition != GetScrollPos(hWnd,SB_VERT)) {
  821.                SetScrollPos(hWnd,SB_VERT,yposition,TRUE);
  822.                InvalidateRect(hWnd,NULL,TRUE);
  823.                }
  824.             set_win_offset();
  825.             break;
  826.  
  827.         case WM_CLOSE:
  828.             win_kill_all_zooming();
  829.             goto GlobalExit;
  830.  
  831.         case WM_COMMAND:
  832.             switch (wParam) {
  833.  
  834.                case IDM_RESTART:
  835.                case IDF_RESTART:
  836.                    win_cmdfiles();
  837.                    time_to_reinit  = 1;
  838.                    time_to_cycle = 0;
  839.                    calc_status = 0;
  840.                    break;
  841.  
  842.                case IDM_HELP_INDEX:
  843.                case IDF_HELP_INDEX:
  844.                    WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
  845.                    break;
  846.  
  847.                case IDM_HELP_FRACTINT:
  848.                case IDF_HELP_FRACTINT:
  849.                    fractint_help();
  850.                    break;
  851.  
  852.                case IDM_HELP_KEYBOARD:
  853.            WinHelp(hWnd,szHelpFileName,HELP_KEY,(DWORD)(LPSTR)"keys");
  854.                    break;
  855.  
  856.                case IDM_HELP_HELP:
  857.            WinHelp(hWnd,"WINHELP.HLP",HELP_INDEX,0L);
  858.                    break;
  859.             
  860.                 case IDF_FRACTINTSTYLE:
  861.                     winfract_menustyle = TRUE;
  862.             hMenu = GetMenu(hWnd);
  863.             CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_CHECKED);
  864.             CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_UNCHECKED);
  865.                     SaveParamSwitch(FractintMenusStr, winfract_menustyle);
  866.                     break;
  867.             
  868.                 case IDF_WINFRACTSTYLE:
  869.                     winfract_menustyle = FALSE;
  870.             hMenu = GetMenu(hWnd);
  871.             CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_UNCHECKED);
  872.             CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_CHECKED);
  873.                     SaveParamSwitch(FractintMenusStr, winfract_menustyle);
  874.                     break;
  875.             
  876.                 case IDM_COORD:
  877.                     CoordinateBox(hWnd);
  878.                     break;
  879.                 case IDM_ABOUT:
  880.                     lpProcAbout = MakeProcInstance(About, hInst);
  881.                     DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
  882.                     FreeProcInstance(lpProcAbout);
  883.                     break;
  884.                    
  885.                 case IDM_COPY:
  886.                    /* allocate the memory for the BITMAPINFO structure 
  887.                       (followed by the bitmap bits) */
  888.                    if (!(hClipboard1 = GlobalAlloc(GMEM_FIXED,
  889.                    sizeof(BITMAPINFOHEADER)+colors*sizeof(PALETTEENTRY)
  890.                    + win_bitmapsize))) {
  891.                         cant_clip();
  892.                         return(TRUE);
  893.                         }
  894.                     if (!(lpClipboard1 =
  895.                         (LPSTR) GlobalLock(hClipboard1))) {
  896.                         GlobalFree(hClipboard1);
  897.                         cant_clip();
  898.                         return(TRUE);
  899.                         }
  900.                     rgb_dib_palette();
  901.                     lmemcpy((char huge *)lpClipboard1, (char huge *)pDibInfo,
  902.                         sizeof(BITMAPINFOHEADER)+colors*sizeof(RGBQUAD)
  903.                         );
  904.                     lpClipboard1 += 
  905.                         (sizeof(BITMAPINFOHEADER))+
  906.                         (colors*sizeof(RGBQUAD));
  907.                     lmemcpy((char huge *)lpClipboard1, (char huge *)pixels,
  908.                         win_bitmapsize);
  909.  
  910.                     GlobalUnlock(hClipboard1);
  911.  
  912.                    /* allocate the memory for the palette info */
  913.                    if (!lpClipboard2) {
  914.                        if (!(hClipboard2 = GlobalAlloc (GMEM_FIXED,
  915.                            (sizeof (LOGPALETTE) +
  916.                            (sizeof (PALETTEENTRY) * (PALETTESIZE)))))) {
  917.                             GlobalFree(hClipboard1);
  918.                             cant_clip();
  919.                             return(TRUE);
  920.                             }
  921.                         if (!(lpClipboard2 = 
  922.                             (LPSTR) GlobalLock(hClipboard2))) {
  923.                             GlobalFree(hClipboard1);
  924.                             GlobalFree(hClipboard2);
  925.                             cant_clip();
  926.                             return(TRUE);
  927.                             }
  928.                        }
  929.                    /* fill in the palette info */
  930.                    lpClipboard2[0] = 0;
  931.                    lpClipboard2[1] = 3;
  932.                    lpClipboard2[2] = 0;
  933.                    lpClipboard2[3] = 1;
  934.                    lmemcpy((char huge *)&lpClipboard2[4],
  935.                         (char huge *)&pDibInfo->bmiColors[0],
  936.                         PALETTESIZE*sizeof(RGBQUAD)
  937.                         );
  938.                    hClipboard3 = CreatePalette ((LPLOGPALETTE) lpClipboard2);
  939.  
  940.                     hDC = GetDC(hWnd);
  941.                     hBitmap = CreateDIBitmap(hDC, &pDibInfo->bmiHeader,
  942.                               CBM_INIT, (LPSTR)pixels, pDibInfo,
  943.                               DIB_RGB_COLORS);
  944.                     ReleaseDC(hWnd, hDC);
  945.  
  946.                     if (OpenClipboard(hWnd)) {
  947.                         EmptyClipboard();
  948.                         SetClipboardData(CF_PALETTE, hClipboard3);
  949.                         SetClipboardData(CF_DIB, hClipboard1);
  950.                         if(hBitmap)
  951.                           SetClipboardData(CF_BITMAP, hBitmap);
  952.                         CloseClipboard();
  953.                         }
  954.  
  955.                     default_dib_palette();
  956.  
  957.                     break;
  958.  
  959.         case IDF_IFS3D:
  960.                     if (winfract_menustyle) {    /* Fractint prompts */
  961.                         extern int display3d, overlay3d;
  962.                         extern int tabmode, helpmode, initbatch;
  963.                         extern char gifmask[];
  964.                         int showfile;
  965.                         tabmode = 0;
  966.                         if (get_fract3d_params() >= 0) {
  967.                             win_kill_all_zooming();
  968.                             time_to_restart = 1;
  969.                             }
  970.                         tabmode = 1;
  971.                         break;
  972.                         }
  973.         case IDM_IFS3D:
  974.             {
  975.             extern int glassestype;
  976.                     lpSelectIFS3D = MakeProcInstance(
  977.                         (FARPROC) SelectIFS3D, hInst);
  978.                     Return = DialogBox(hInst, "SelectIFS3D",
  979.                          hWnd, lpSelectIFS3D);
  980.                     FreeProcInstance(lpSelectIFS3D);
  981.                     if (Return) {
  982.                          win_kill_all_zooming();
  983.                          time_to_restart = 1;
  984.                          if (glassestype) {
  985.                              lpSelectFunnyGlasses = MakeProcInstance(
  986.                                  (FARPROC) SelectFunnyGlasses, hInst);
  987.                              Return = DialogBox(hInst, "SelectFunnyGlasses",
  988.                                  hWnd, lpSelectFunnyGlasses);
  989.                              FreeProcInstance(lpSelectFunnyGlasses);
  990.                              check_funnyglasses_name();
  991.                              }
  992.                          }
  993.                     break;
  994.                     }
  995.  
  996.                 case IDF_OPEN:
  997.                 case IDF_3D:
  998.                 case IDF_3DOVER:
  999.                     if (winfract_menustyle) {    /* Fractint prompts */
  1000.                         extern int display3d, overlay3d;
  1001.                         extern int tabmode, helpmode, initbatch;
  1002.                         extern char gifmask[];
  1003.                         int showfile;
  1004.                         char *hdg;
  1005.                         
  1006.                         win_kill_all_zooming();
  1007.                         time_to_resume = 1;
  1008.                         initbatch = 0;
  1009.                         display3d = 0;
  1010.                         overlay3d = 0;
  1011.                         if (wParam == IDM_3D || wParam == IDM_3DOVER
  1012.                             || wParam == IDF_3D || wParam == IDF_3DOVER)
  1013.                             display3d = 1;
  1014.                         if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1015.                             overlay3d = 1;
  1016.                         win_display3d = 0;
  1017.                         win_overlay3d = 0;
  1018.                         stackscreen();
  1019.                         tabmode = 0;
  1020.                         showfile = -1;
  1021.                         while (showfile <= 0) {        /* image is to be loaded */
  1022.                             if (overlay3d)
  1023.                                 hdg = "Select File for 3D Overlay";
  1024.                             else if (display3d)
  1025.                                 hdg = "Select File for 3D Transform";
  1026.                             else
  1027.                                 hdg = "Select File to Restore";
  1028.                             if (showfile < 0 &&
  1029.                                 getafilename(hdg,gifmask,readname) < 0) {
  1030.                             showfile = 1;             /* cancelled */
  1031.                             break;
  1032.                             }
  1033.                             showfile = 0;
  1034.                             tabmode = 1;
  1035.                             if (read_overlay() == 0)         /* read hdr, get video mode */
  1036.                             break;              /* got it, exit */
  1037.                             showfile = -1;             /* retry */
  1038.                             }
  1039.                         if (!showfile) {
  1040.                             lstrcpy(FileName, readname);
  1041.                             time_to_load = 1;
  1042.                             time_to_cycle = 0;
  1043.                             if (wParam == IDM_3D || wParam == IDM_3DOVER
  1044.                                 || wParam == IDF_3D || wParam == IDF_3DOVER)
  1045.                                 win_display3d = 1;
  1046.                             if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1047.                                 win_overlay3d = 1;
  1048.                             }
  1049.                         tabmode = 1;
  1050.                         unstackscreen();
  1051.                         break;
  1052.                         }
  1053.                 case IDM_NEW:
  1054.                 case IDM_OPEN:
  1055.                 case IDM_3D:
  1056.                 case IDM_3DOVER:
  1057.                     win_display3d = 0;
  1058.                     win_overlay3d = 0;
  1059.                     /* Call OpenDlg() to get the filename */
  1060.                     lstrcpy(DialogTitle,"Select a File to Open");
  1061.                     if (wParam == IDM_3D || wParam == IDF_3D)
  1062.                         lstrcpy(DialogTitle,"Select a File for 3D");
  1063.                     if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1064.                         lstrcpy(DialogTitle,"Select a File for 3D Overlay");
  1065.                     lstrcpy(FileName, readname);
  1066.                     lstrcpy(DefSpec,"*.gif");
  1067.                     lstrcpy(DefExt,".gif");
  1068.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1069.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1070.                     FreeProcInstance(lpOpenDlg);
  1071.                     if (Return && (wParam == IDM_3D || wParam == IDM_3DOVER)) {
  1072.                 extern int glassestype;
  1073.                         lpSelect3D = MakeProcInstance(
  1074.                             (FARPROC) Select3D, hInst);
  1075.                         Return = DialogBox(hInst, "Select3D",
  1076.                              hWnd, lpSelect3D);
  1077.                         FreeProcInstance(lpSelect3D);
  1078.                          if (glassestype) {
  1079.                              int Return2;
  1080.                              lpSelectFunnyGlasses = MakeProcInstance(
  1081.                                  (FARPROC) SelectFunnyGlasses, hInst);
  1082.                              Return2 = DialogBox(hInst, "SelectFunnyGlasses",
  1083.                                  hWnd, lpSelectFunnyGlasses);
  1084.                              FreeProcInstance(lpSelectFunnyGlasses);
  1085.                              check_funnyglasses_name();
  1086.                              }
  1087.                         if (Return && !win_3dspherical) {
  1088.                             lpSelect3DPlanar = MakeProcInstance(
  1089.                                 (FARPROC) Select3DPlanar, hInst);
  1090.                             Return = DialogBox(hInst, "Select3DPlanar",
  1091.                                  hWnd, lpSelect3DPlanar);
  1092.                             FreeProcInstance(lpSelect3DPlanar);
  1093.                             }
  1094.                         if (Return && win_3dspherical) {
  1095.                             lpSelect3DSpherical = MakeProcInstance(
  1096.                                 (FARPROC) Select3DSpherical, hInst);
  1097.                             Return = DialogBox(hInst, "Select3DSpherical",
  1098.                                  hWnd, lpSelect3DSpherical);
  1099.                             FreeProcInstance(lpSelect3DSpherical);
  1100.                             }
  1101.                         if (Return && (ILLUMINE || RAY)) {
  1102.                             lpSelectLightSource = MakeProcInstance(
  1103.                                 (FARPROC) SelectLightSource, hInst);
  1104.                             Return = DialogBox(hInst, "SelectLightSource",
  1105.                                  hWnd, lpSelectLightSource);
  1106.                             FreeProcInstance(lpSelectLightSource);
  1107.                             }
  1108.                         }
  1109.                     if (Return) {
  1110.                         lstrcpy(readname,FileName);
  1111.                         time_to_load = 1;
  1112.                         win_kill_all_zooming();
  1113.                         time_to_cycle = 0;
  1114.                         if (wParam == IDM_3D || wParam == IDM_3DOVER
  1115.                          || wParam == IDF_3D || wParam == IDF_3DOVER)
  1116.                             win_display3d = 1;
  1117.                         if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1118.                             win_overlay3d = 1;
  1119.                         }
  1120.                     break;
  1121.  
  1122.                 case IDF_MAPIN:
  1123.                     if (winfract_menustyle) {  /* fractint-style prompts */
  1124.                         win_kill_all_zooming();
  1125.                         time_to_resume = 1;
  1126.                         time_to_cycle = 0;
  1127.                         if (wParam == IDF_MAPIN)
  1128.                             load_palette();
  1129.                         else
  1130.                             save_palette();
  1131.                         spindac(0,1);
  1132.                         break;
  1133.                         }
  1134.                 case IDF_MAPOUT:
  1135.                 case IDM_MAPIN:
  1136.                 case IDM_MAPOUT:
  1137.                     /* Call OpenDlg() to get the filename */
  1138.                     lstrcpy(DialogTitle,"Select a Palette File");
  1139.                     lstrcpy(FileName, "default");
  1140.                     if (wParam == IDM_MAPOUT || wParam == IDF_MAPOUT)
  1141.                         lstrcpy(FileName, "mymap");
  1142.                     lstrcpy(DefSpec,"*.map");
  1143.                     lstrcpy(DefExt,".map");
  1144.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1145.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1146.                     FreeProcInstance(lpOpenDlg);
  1147.                     if (Return && (wParam == IDM_MAPIN || wParam == IDF_MAPIN)) {
  1148.                         win_kill_all_zooming();
  1149.                         ValidateLuts(FileName);
  1150.                         spindac(0,1);
  1151.                         }
  1152.                     if (Return && (wParam == IDM_MAPOUT || wParam == IDF_MAPOUT)) {
  1153.                         FILE *dacfile;
  1154.             dacfile = fopen(FileName,"w");
  1155.             if (dacfile == NULL) {
  1156.                 break;
  1157.                 }
  1158.             fprintf(dacfile,"  0   0   0\n");
  1159.             for (i = 1; i < 256; i++)
  1160.                 fprintf(dacfile, "%3d %3d %3d\n",
  1161.                 dacbox[i][0] << 2,
  1162.                 dacbox[i][1] << 2,
  1163.                 dacbox[i][2] << 2);
  1164.             fclose(dacfile);
  1165.                         }
  1166.                     break;
  1167.  
  1168.                 case IDF_SAVE:
  1169.                     if (winfract_menustyle) {    /* Fractint prompts */
  1170.                         /* (no change) */
  1171.                         }
  1172.                 case IDM_SAVE:
  1173.                 case IDM_SAVEAS:
  1174.                     /* Call the SaveAsDlg() function to get the new filename */
  1175.                     lstrcpy(DialogTitle,"Select a File to Save");
  1176.                     lstrcpy(FileName, readname);
  1177.  
  1178.                     /* MCP 10-27-91, Moved to DIALOG.C
  1179.                     lstrcpy(DefSpec,"*.gif");
  1180.                     lstrcpy(DefExt,".gif");
  1181.                     */
  1182.  
  1183.                     lpSaveAsDlg = MakeProcInstance(SaveAsDlg, hInst);
  1184.                     DialogBox(hInst, "SaveAs", hWnd, lpSaveAsDlg);
  1185.                     FreeProcInstance(lpSaveAsDlg);
  1186.                     if (time_to_save)
  1187.                     {
  1188.                        time_to_cycle = 0;
  1189.                        wsprintf(StatusTitle, "Saving:  %s", (LPSTR)FullPathName);
  1190.                        OpenStatusBox(hWnd, hInst);
  1191.                        resave_flag = overwrite = 1;
  1192.                     }
  1193.                     break;
  1194.  
  1195.         case IDM_SIZING:
  1196.                     win_kill_all_zooming();
  1197.             WindowSizing(hWnd);
  1198.             break;
  1199.  
  1200.         case IDM_ORBITS:
  1201.             /* toggle orbits only if in pixel-by-pixel mode */
  1202.             if (win_fastupdate)
  1203.                         time_to_orbit = 1;
  1204.                 break;
  1205.  
  1206.                 case IDM_PIXELS:
  1207.                     {
  1208.                     BOOL profile_fastupdate;
  1209.             hMenu = GetMenu(hWnd);
  1210.                     if (win_fastupdate) {
  1211.                         win_fastupdate = 0;
  1212.                         /* if disabling p-by-p, disable orbits, too */
  1213.                         if (show_orbit)
  1214.                             time_to_orbit = 1;
  1215.                         profile_fastupdate = FALSE;
  1216.                         CheckMenuItem(hMenu, IDM_PIXELS, MF_UNCHECKED);
  1217.                         }
  1218.                     else {
  1219.                         win_fastupdate = 2;
  1220.                         profile_fastupdate = TRUE;
  1221.                         CheckMenuItem(hMenu, IDM_PIXELS, MF_CHECKED);
  1222.                         }
  1223.                     SaveParamSwitch(FractintPixelsStr, profile_fastupdate);
  1224.                     }
  1225.                     break;
  1226.  
  1227.                 case IDF_PRINT:
  1228.                     if (winfract_menustyle) {    /* Fractint prompts */
  1229.                         /* (no change) */
  1230.                         }
  1231.                 case IDM_PRINT:
  1232.                     time_to_print = 1;
  1233.                     time_to_cycle = 0;
  1234.                     break;
  1235.  
  1236.                 case IDM_PARFILE:
  1237. winfract_loadpar:
  1238.                     {
  1239.                     FILE *parmfile;
  1240.                     extern char CommandFile[];
  1241.                     extern char CommandName[];
  1242.                     long point;
  1243.                     
  1244.                     win_kill_all_zooming();
  1245.                     lstrcpy(DialogTitle,"Select a Parameter File");
  1246.                     lstrcpy(FileName, CommandFile);
  1247.                     lstrcpy(DefSpec,"*.par");
  1248.                     lstrcpy(DefExt,".par");
  1249.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1250.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1251.                     FreeProcInstance(lpOpenDlg);
  1252.                     if (Return) {
  1253.                         lstrcpy(LFileName, FileName);
  1254.                         lstrcpy(CommandFile, FileName);
  1255.                         get_lsys_name();
  1256.                         lstrcpy(DialogTitle,"Select a Parameter Entry");
  1257.                         win_choicemade = 0;
  1258.                         lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1259.                         Return = DialogBox(hInst, "SelectFractal",
  1260.                             hWnd, lpSelectFractal);
  1261.                         FreeProcInstance(lpSelectFractal);
  1262.                         if (Return) { 
  1263.                             parmfile = fopen(CommandFile,"rb");
  1264.                             memcpy((char *)&point,
  1265.                                 (char *)&win_choices[win_choicemade][21],
  1266.                                 4);
  1267.                             fseek(parmfile,point,SEEK_SET);
  1268.                             Return = load_commands(parmfile);
  1269.                             }
  1270.                         if (Return) {
  1271.                             if (xx3rd != xxmin || yy3rd != yymin)
  1272.                                 stopmsg(0," This image uses a skewed zoom-box,\n a feature not available in Winfract.\n All Skewness has been dropped"); 
  1273.                             if (colorpreloaded)
  1274.                                 win_savedac();
  1275.                         maxiter = maxit;
  1276.                     time_to_restart = 1;
  1277.                     time_to_cycle = 0;
  1278.                     calc_status = 0;
  1279.                             }
  1280.                         }
  1281.                     break;
  1282.                     }
  1283.  
  1284.                 case IDF_FORMULA:
  1285.                     if (winfract_menustyle) {    /* Fractint prompts */
  1286.                         win_kill_all_zooming();
  1287.                         time_to_resume = 1;
  1288.                     stackscreen();
  1289.             i = get_fracttype();
  1290.                     unstackscreen();
  1291.                     SetFocus(hWnd);
  1292.                     if (i == 0) {        /* time to redraw? */
  1293.                     time_to_restart = 1;
  1294.                     time_to_cycle = 0;
  1295.                     calc_status = 0;
  1296.                     }
  1297.                     break;
  1298.                         }
  1299.                 case IDM_FORMULA:
  1300.                     lstrcpy(DialogTitle,"Select a Fractal Formula");
  1301.                     win_kill_all_zooming();
  1302.                     win_numchoices = CountFractalList;
  1303.                     win_choicemade = 0;
  1304.                     CurrentFractal = fractype;
  1305.                     for (i = 0; i < win_numchoices; i++) {
  1306.                         win_choices[i] = fractalspecific[onthelist[i]].name;
  1307.                         if (onthelist[i] == fractype ||
  1308.                             fractalspecific[onthelist[i]].tofloat == fractype)
  1309.                             win_choicemade = i;
  1310.                         }
  1311.                     lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1312.                     Return = DialogBox(hInst, "SelectFractal",
  1313.                         hWnd, lpSelectFractal);
  1314.                     FreeProcInstance(lpSelectFractal);
  1315.                     fchoice = win_choicemade;
  1316.                     if (Return && (onthelist[fchoice] == IFS ||
  1317.                         onthelist[fchoice] == IFS3D)) {
  1318.                         lstrcpy(DialogTitle,"Select an IFS Filename");
  1319.                         lstrcpy(FileName, IFSFileName);
  1320.                         lstrcpy(DefSpec,"*.ifs");
  1321.                         lstrcpy(DefExt,".ifs");
  1322.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1323.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1324.                         FreeProcInstance(lpOpenDlg);
  1325.                         if (Return) {
  1326.                             lstrcpy(IFSFileName, FileName);
  1327.                             lstrcpy(FormFileName, FileName);
  1328.                             get_formula_names();
  1329.                             lstrcpy(DialogTitle,"Select an IFS type");
  1330.                             win_choicemade = 0;
  1331.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1332.                             Return = DialogBox(hInst, "SelectFractal",
  1333.                                 hWnd, lpSelectFractal);
  1334.                             FreeProcInstance(lpSelectFractal);
  1335.                             if (Return) {
  1336.                                 lstrcpy(IFSName, win_choices[win_choicemade]);
  1337.                                 Return = ! ifsload();
  1338.                                 }
  1339.                             }
  1340.                         }
  1341.                     if (Return && (onthelist[fchoice] == FORMULA || 
  1342.                         onthelist[fchoice] == FFORMULA)) {
  1343.                         /* obtain the formula filename */
  1344.                         lstrcpy(DialogTitle,"Select a Formula File");
  1345.                         lstrcpy(FileName, FormFileName);
  1346.                         lstrcpy(DefSpec,"*.frm");
  1347.                         lstrcpy(DefExt,".frm");
  1348.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1349.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1350.                         FreeProcInstance(lpOpenDlg);
  1351.                         if (Return) {
  1352.                             lstrcpy(FormFileName, FileName);
  1353.                             get_formula_names();
  1354.                             lstrcpy(DialogTitle,"Select a Formula");
  1355.                             win_choicemade = 0;
  1356.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1357.                             Return = DialogBox(hInst, "SelectFractal",
  1358.                                 hWnd, lpSelectFractal);
  1359.                             FreeProcInstance(lpSelectFractal);
  1360.                             if (Return) 
  1361.                                 Return = parse_formula_names();
  1362.                             }
  1363.                         }
  1364.                     if (Return && (onthelist[fchoice] == LSYSTEM)) {
  1365.                         /* obtain the lsystem formula filename */
  1366.                         lstrcpy(DialogTitle,"Select an Lsystem File");
  1367.                         lstrcpy(FileName, LFileName);
  1368.                         lstrcpy(DefSpec,"*.l");
  1369.                         lstrcpy(DefExt,".l");
  1370.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1371.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1372.                         FreeProcInstance(lpOpenDlg);
  1373.                         if (Return) {
  1374.                             lstrcpy(LFileName, FileName);
  1375.                             get_lsys_name();
  1376.                             lstrcpy(DialogTitle,"Select a Formula");
  1377.                             win_choicemade = 0;
  1378.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1379.                             Return = DialogBox(hInst, "SelectFractal",
  1380.                                 hWnd, lpSelectFractal);
  1381.                             FreeProcInstance(lpSelectFractal);
  1382.                             if (Return) {
  1383.                                 lstrcpy(LName, win_choices[win_choicemade]);
  1384.                                 Return = !LLoad();
  1385.                                 }
  1386.                             }
  1387.                         }
  1388.                     if (Return) {
  1389.                         CurrentFractal = onthelist[fchoice];
  1390.                         curfractalspecific = &fractalspecific[CurrentFractal];
  1391.                         set_default_parms();
  1392.                         lpSelectFracParams = MakeProcInstance(SelectFracParams,
  1393.                             hInst);
  1394.                         Return = DialogBox(hInst, "SelectFracParams",
  1395.                             hWnd, lpSelectFracParams);
  1396.                         FreeProcInstance(lpSelectFracParams);
  1397.                         }
  1398.                     if (Return) {
  1399.             restoredac();
  1400.                         time_to_reinit = 1;
  1401.                         time_to_cycle = 0;
  1402.                         calc_status = 0;
  1403.                         }
  1404.                     break;
  1405.  
  1406.                 case IDF_IMAGE:
  1407.                     if (winfract_menustyle) {    /* Fractint prompts */
  1408.                         /* (no change) */
  1409.                         }
  1410.                 case IDM_IMAGE:
  1411.                         win_kill_all_zooming();
  1412.             lpSelectImage = MakeProcInstance(SelectImage, hInst);
  1413.             Return = DialogBox(hInst, "SelectImage",
  1414.                 hWnd, lpSelectImage);
  1415.             FreeProcInstance(lpSelectImage);
  1416.             if (Return) {
  1417.                 restoredac();
  1418.                 time_to_restart = 1;
  1419.                                 time_to_cycle = 0;
  1420.                                 calc_status = 0;
  1421.                 }
  1422.             ReSizeWindow(hWnd);
  1423.                         break;
  1424.  
  1425.                 case IDM_SAVEPAR:
  1426.                     win_kill_all_zooming();
  1427.             lpSelectSavePar = MakeProcInstance(SelectSavePar, hInst);
  1428.             Return = DialogBox(hInst, "SelectSavePar",
  1429.              hWnd, lpSelectSavePar);
  1430.             FreeProcInstance(lpSelectSavePar);
  1431.             if (Return) {
  1432.                 time_to_resume = 1;
  1433.                 win_make_batch_file();
  1434.              }
  1435.                     break;
  1436.  
  1437.                 case IDF_SAVEPAR:
  1438.                     win_kill_all_zooming();
  1439.                     time_to_resume = 1;
  1440.                     make_batch_file();
  1441.                     break;
  1442.  
  1443.                 case IDF_PARFILE:
  1444.                     if (!winfract_menustyle) {    /* winfract prompts */
  1445.                         goto winfract_loadpar; /* for now */
  1446.                         }
  1447.                 case IDF_DOODADX:
  1448.                     if (!winfract_menustyle)   /* Windows menus */
  1449.                         goto winfract_xmenu;   /* for now */
  1450.                 case IDF_DOODADY:
  1451.                     if (!winfract_menustyle)   /* Windows menus */
  1452.                         goto winfract_ymenu;   /* for now */
  1453.                 case IDF_DOODADZ:
  1454.                     if (!winfract_menustyle)   /* Windows menus */
  1455.                         goto winfract_zmenu;   /* for now */
  1456.  
  1457.                     if (winfract_menustyle) {    /* fractint prompts */
  1458.                         win_kill_all_zooming();
  1459.                         time_to_resume = 1;
  1460.                     stackscreen();
  1461.                     maxiter = maxit;
  1462.                         if (wParam == IDF_DOODADX || wParam == IDM_DOODADX)
  1463.                             i = get_toggles();
  1464.                         else if (wParam == IDF_DOODADY || wParam == IDM_DOODADY)
  1465.                             i = get_toggles2();
  1466.                         else if (wParam == IDF_DOODADZ || wParam == IDM_DOODADZ)
  1467.                             i = get_fract_params(1);
  1468.                         else {
  1469.                 i = get_commands();
  1470.                             if (xx3rd != xxmin || yy3rd != yymin)
  1471.                                 stopmsg(0," This image uses a skewed zoom-box,\n a feature not available in Winfract.\n All Skewness has been dropped"); 
  1472.                 if (colorpreloaded)
  1473.                     win_savedac();
  1474.                 }
  1475.                     unstackscreen();
  1476.                     SetFocus(hWnd);
  1477.                         time_to_cycle = 0;
  1478.                     if (i > 0) {        /* time to redraw? */
  1479.                         maxiter = maxit;
  1480.                     time_to_restart = 1;
  1481.                     calc_status = 0;
  1482.                     }
  1483.                     break;
  1484.                    }
  1485.  
  1486.                 case IDM_DOODADX:
  1487. winfract_xmenu:
  1488.             lpSelectDoodads = MakeProcInstance(SelectDoodads, hInst);
  1489.             Return = DialogBox(hInst, "SelectDoodads",
  1490.                 hWnd, lpSelectDoodads);
  1491.             FreeProcInstance(lpSelectDoodads);
  1492.             if (Return) {
  1493.                                 win_kill_all_zooming();
  1494.                 win_savedac();
  1495.                 time_to_restart = 1;
  1496.                                 time_to_cycle = 0;
  1497.                                 calc_status = 0;
  1498.                 }
  1499.                         break;
  1500.  
  1501.                 case IDM_DOODADY:
  1502. winfract_ymenu:
  1503.             lpSelectExtended = MakeProcInstance(SelectExtended, hInst);
  1504.             Return = DialogBox(hInst, "SelectExtended",
  1505.                 hWnd, lpSelectExtended);
  1506.             FreeProcInstance(lpSelectExtended);
  1507.             if (Return) {
  1508.                                 win_kill_all_zooming();
  1509.                 win_savedac();
  1510.                 time_to_restart = 1;
  1511.                                 time_to_cycle = 0;
  1512.                                 calc_status = 0;
  1513.                 }
  1514.                         break;
  1515.  
  1516.            case IDM_DOODADZ:
  1517. winfract_zmenu:
  1518.             CurrentFractal = fractype;
  1519.                     lpSelectFracParams = MakeProcInstance(SelectFracParams,
  1520.                         hInst);
  1521.                     Return = DialogBox(hInst, "SelectFracParams",
  1522.                         hWnd, lpSelectFracParams);
  1523.                     FreeProcInstance(lpSelectFracParams);
  1524.                     if (Return) {
  1525.                         win_kill_all_zooming();
  1526.             win_savedac();
  1527.                         time_to_reinit = 1;
  1528.                         time_to_cycle = 0;
  1529.                         calc_status = 0;
  1530.                         }
  1531.               break;
  1532.  
  1533.                case IDF_STARFIELD:
  1534.                    if (winfract_menustyle) {    /* fractint prompts */
  1535.                        if (get_starfield_params() >= 0) {
  1536.                            win_kill_all_zooming();
  1537.                            time_to_starfield = 1;
  1538.                            time_to_cycle = 0;
  1539.                            calc_status = 0;
  1540.                            }
  1541.                        break;
  1542.                        }
  1543.                case IDM_STARFIELD:
  1544.                    lpSelectStarfield = MakeProcInstance(
  1545.                        (FARPROC) SelectStarfield, hInst);
  1546.                    Return = DialogBox(hInst, "Starfield",
  1547.                         hWnd, lpSelectStarfield);
  1548.                    FreeProcInstance(lpSelectStarfield);
  1549.                    if (Return) {
  1550.                        win_kill_all_zooming();
  1551.                        time_to_starfield = 1;
  1552.                        time_to_cycle = 0;
  1553.                        calc_status = 0;
  1554.                        }
  1555.                    break;
  1556.  
  1557.                case IDF_HOTNOZOOM:
  1558.                   win_kill_all_zooming();
  1559.                   if(Zooming)
  1560.                      CancelZoom();
  1561.                   else if(bMove)
  1562.                   {
  1563.                      extern POINT Center;
  1564.  
  1565.                      EndSelection(Center, &Rect);
  1566.  
  1567.                      ClearSelection(hWnd, &Rect, Shape);
  1568.                      bMove = bMoving = bTrack = FALSE;
  1569.                   }
  1570.                   break;
  1571.  
  1572.                 case IDF_CYCLE:
  1573.                     if (winfract_menustyle) {    /* Fractint prompts */
  1574.                         /* (no change) */
  1575.                         }
  1576.                 case IDM_CYCLE:
  1577.                     if (!win_oktocycle())
  1578.                         break;
  1579.                     win_kill_all_zooming();
  1580.                     lpSelectCycle = MakeProcInstance(SelectCycle, hInst);
  1581.                     Return = DialogBox(hInst, "SelectCycle",
  1582.                     hWnd, lpSelectCycle);
  1583.                     FreeProcInstance(lpSelectCycle);
  1584.                     break;
  1585.  
  1586.                case IDF_HOTCYCLEON:
  1587.                /* Space/etc.. toggles Color-cycling parameters */
  1588.                    win_kill_all_zooming();
  1589.                    if (time_to_cycle == 1)
  1590.                        time_to_cycle = 0;
  1591.                    else
  1592.                        if (win_oktocycle()) {
  1593.                             time_to_cycle = 1;
  1594.                             colorstate = 1;
  1595.                             }
  1596.                    break;
  1597.                    
  1598.                case IDF_HOTCYCLERIGHT: 
  1599.                    win_kill_all_zooming();
  1600.                    if (win_oktocycle()) {
  1601.                        time_to_cycle = 1;
  1602.                        win_cycledir = -1;
  1603.                        colorstate = 1;
  1604.                        }
  1605.                    break;
  1606.  
  1607.                case IDF_HOTCYCLELEFT: 
  1608.                    win_kill_all_zooming();
  1609.                    if (win_oktocycle()) {
  1610.                        time_to_cycle = 1;
  1611.                        win_cycledir = 1;
  1612.                        colorstate = 1;
  1613.                        }
  1614.                    break;
  1615.                    
  1616.                case IDF_HOTCYCLERSTEP: 
  1617.                    if (win_oktocycle()) {
  1618.                        time_to_cycle = 0;
  1619.                        win_cycledir = -1;
  1620.                        colorstate = 1;
  1621.                        spindac(win_cycledir,1);
  1622.                        }
  1623.                    break;
  1624.                    
  1625.                case IDF_HOTCYCLELSTEP: 
  1626.                    win_kill_all_zooming();
  1627.                    if (win_oktocycle()) {
  1628.                        time_to_cycle = 0;
  1629.                        win_cycledir = 1;
  1630.                        colorstate = 1;
  1631.                        spindac(win_cycledir,1);
  1632.                        }
  1633.                    break;
  1634.  
  1635.                case IDF_HOTCYCLEFAST: 
  1636.                    win_kill_all_zooming();
  1637.                    if (time_to_cycle != 0 && win_cycledelay > 4)
  1638.                        win_cycledelay -= 5;
  1639.                    break;
  1640.  
  1641.                case IDF_HOTCYCLESLOW: 
  1642.                    win_kill_all_zooming();
  1643.                    if (time_to_cycle != 0 && win_cycledelay < 100)
  1644.                        win_cycledelay += 5;
  1645.                    break;
  1646.  
  1647.                case IDF_HOTCYCLERAND:
  1648.                    if(Zooming)
  1649.                       ExecuteZoom();
  1650.                    else if(bMove)
  1651.                    {
  1652.                        extern POINT Center;
  1653.  
  1654.                        DragPoint = Center;
  1655.                        goto ExecZoom;
  1656.                    }
  1657.                    else if (win_oktocycle()) {
  1658.                        win_kill_all_zooming();
  1659.                        time_to_cycle = 1;
  1660.                        win_cyclerand = 2;
  1661.                        colorstate = 1;
  1662.                        }
  1663.                    break;
  1664.  
  1665.                 case IDM_MATH_TOOLS:
  1666.                     MathToolBox(hWnd);
  1667.                     break;
  1668.  
  1669.                 case IDM_ZOOMOUT:
  1670.                 case IDM_ZOOMIN:
  1671.                     if(ZoomBarOpen)
  1672.                        ZoomBar(hWnd);
  1673.                     else
  1674.                        CheckMenuItem(GetMenu(hWnd), ZoomMode, MF_UNCHECKED);
  1675.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  1676.                     ZoomMode = wParam;
  1677.                     break;
  1678.  
  1679.                 case IDM_ZOOM:
  1680.                     if(!ZoomBarOpen)
  1681.                        CheckMenuItem(GetMenu(hWnd), ZoomMode, MF_UNCHECKED);
  1682.                     win_kill_all_zooming();
  1683.                     ZoomBar(hWnd);
  1684.                     break;
  1685.  
  1686.                 case IDF_STATUS:
  1687.                     if (winfract_menustyle) {    /* Fractint prompts */
  1688.                         tab_display();
  1689.                         break;
  1690.                         }
  1691.                 case IDS_STATUS:
  1692.                     lpProcStatus = MakeProcInstance(Status, hInst);
  1693.                     DialogBox(hInst, "ShowStatus", hWnd, lpProcStatus);
  1694.                     FreeProcInstance(lpProcStatus);
  1695.                     break;
  1696.  
  1697.                 GlobalExit:
  1698.                 case IDM_EXIT:
  1699.                     win_kill_all_zooming();
  1700.                     time_to_quit = 1;
  1701.                     time_to_cycle = 0;
  1702.                     ValidateRect(hWnd, NULL);
  1703.                     hWndCopy = hWnd;
  1704.                     /* the main routine will actually call 'DestroyWindow()' */
  1705.                     break;
  1706.  
  1707.                 case IDC_EDIT:
  1708.                     if (HIWORD (lParam) == EN_ERRSPACE) {
  1709.                         MessageBox (
  1710.                               GetFocus ()
  1711.                             , "Out of memory."
  1712.                             , "Fractint For Windows"
  1713.                             , MB_ICONSTOP | MB_OK
  1714.                         );
  1715.                     }
  1716.                     break;
  1717.  
  1718.             } 
  1719.             break;
  1720.  
  1721.         case WM_PAINT:
  1722.             if (screen_to_be_cleared && last_written_y < 0) {
  1723.                  /* an empty window */
  1724.                  screen_to_be_cleared = 0;
  1725.                  GetUpdateRect(hWnd, &tempRect, TRUE);
  1726.                  hDC = BeginPaint(hWnd,&ps);
  1727.                  if (last_written_y == -2)
  1728.                      last_written_y = -1;
  1729.                  else
  1730.                      BitBlt(hDC, 0, 0, xdots, ydots,
  1731.                          NULL, 0, 0, BLACKNESS);
  1732.                  ValidateRect(hWnd, &tempRect);
  1733.                  EndPaint(hWnd,&ps);
  1734.                  break;
  1735.                  }
  1736.             if(IsIconic(hWnd)) {
  1737.                int x, y;
  1738.                LPSTR icon;
  1739.                long lx, ly, dlx, dly;
  1740.                DWORD tSize, tWidth, tHeight;
  1741.  
  1742.                if((icon = GlobalLock(hIconBitmap)) == NULL)
  1743.                   break;
  1744.  
  1745.                dlx = ((long)xdots << 8) / IconWidth;
  1746.                dly = ((long)ydots << 8) / IconHeight;
  1747.                for(ly = y = 0; y < IconHeight; y++, ly += dly)
  1748.                {
  1749.                   for(lx = x = 0; x < IconWidth; x++, lx += dlx)
  1750.                   {
  1751.                      unsigned ix, iy;
  1752.                      unsigned char color;
  1753.  
  1754.                      ix = lx >> 8;
  1755.                      iy = ly >> 8;
  1756.                      color = getcolor(ix, iy);
  1757.  
  1758.                      ix = IconWidth - y - 1;
  1759.                      ix = (ix * IconWidth) + x;
  1760.                      iy = ix & pixels_per_bytem1;
  1761.                      ix = ix >> pixelshift_per_byte;
  1762.                      icon[ix] = (icon[ix] & win_notmask[iy]) +
  1763.                                (color << win_bitshift[iy]);
  1764.                   }
  1765.                }
  1766.  
  1767.                hDC = BeginPaint(hWnd, &ps);
  1768.  
  1769.                SelectPalette (hDC, hPal, 0);
  1770.                RealizePalette(hDC);
  1771.  
  1772.                tSize   = pDibInfo->bmiHeader.biSizeImage;
  1773.                tHeight = pDibInfo->bmiHeader.biHeight;
  1774.                tWidth  = pDibInfo->bmiHeader.biWidth;
  1775.  
  1776.                pDibInfo->bmiHeader.biSizeImage = IconSize;
  1777.                pDibInfo->bmiHeader.biHeight    = IconHeight;
  1778.                pDibInfo->bmiHeader.biWidth     = IconWidth;
  1779.  
  1780.                SetDIBitsToDevice(hDC,
  1781.                        2, 2,
  1782.                        IconWidth, IconHeight,
  1783.                        0, 0,
  1784.                        0, IconHeight,
  1785.                        icon, (LPBITMAPINFO)pDibInfo,
  1786.                        DIB_PAL_COLORS);
  1787.  
  1788.                pDibInfo->bmiHeader.biSizeImage = tSize;
  1789.                pDibInfo->bmiHeader.biHeight    = tHeight;
  1790.                pDibInfo->bmiHeader.biWidth     = tWidth;
  1791.  
  1792.                GlobalUnlock(hIconBitmap);
  1793.  
  1794.                EndPaint(hWnd, &ps);
  1795.                break;
  1796.             }
  1797.             screen_to_be_cleared = 0;
  1798.             GetUpdateRect(hWnd, &tempRect, FALSE);
  1799.             PaintMathTools();
  1800.             hDC = BeginPaint(hWnd,&ps);
  1801.             if (last_written_y >= 0) {
  1802.               int top, bottom, left, right, xcount, ycount;
  1803.               /* bit-blit the invalidated bitmap area */
  1804.               int fromleft, fromtop, fromright, frombottom;
  1805.               long firstpixel;
  1806.               top    = tempRect.top;
  1807.               bottom = tempRect.bottom;
  1808.               left   = tempRect.left;
  1809.               right  = tempRect.right;
  1810.               if (bottom >  ydots) bottom = ydots;
  1811.               if (right  >= xdots) right  = xdots-1;
  1812.               if (top    >  ydots) top    = ydots;
  1813.               if (left   >= xdots) left   = xdots;
  1814.               fromleft  = left  + win_xoffset;
  1815.               fromright = right + win_xoffset;
  1816.               fromtop    = top    + win_yoffset;
  1817.               frombottom = bottom + win_yoffset;
  1818.               xcount = fromright - fromleft + 1;
  1819.               ycount = frombottom - fromtop;
  1820.               firstpixel = win_ydots - frombottom;
  1821.               firstpixel = firstpixel * bytes_per_pixelline;
  1822.               if (left < xdots && top < ydots) {
  1823.                   SelectPalette (hDC, hPal, 0);
  1824.                   RealizePalette(hDC);
  1825.                   SetMapMode(hDC,MM_TEXT);
  1826.                   SetDIBitsToDevice(hDC,
  1827.                        left, top,
  1828.                        xcount, ycount,
  1829.                        fromleft, 0,
  1830.                        0, ydots,
  1831.                        (LPSTR)&pixels[firstpixel], (LPBITMAPINFO)pDibInfo,
  1832.                        DIB_PAL_COLORS);
  1833.                   }
  1834.               }
  1835.             ValidateRect(hWnd, &tempRect);
  1836.             EndPaint(hWnd,&ps);
  1837.             PaintMathTools();
  1838.             last_time = time(NULL);  /* reset the "end-paint" time */
  1839.             break;
  1840.  
  1841.         case WM_DESTROY:
  1842.             win_kill_all_zooming();
  1843.             if (win_systempaletteused)
  1844.                 win_stop_cycling();
  1845.             SaveParameters(hWnd);
  1846.             /* delete the handle to the logical palette if it has any
  1847.                color entries and quit. */
  1848.             if (pLogPal->palNumEntries)
  1849.                 DeleteObject (hPal);
  1850.             time_to_quit = 1;
  1851.             time_to_cycle = 0;
  1852.             WinHelp(hWnd,szHelpFileName,HELP_QUIT,0L);
  1853.             GlobalFree(hIconBitmap);
  1854.             PostQuitMessage(0);
  1855.             hWndCopy = hWnd;
  1856.             break;
  1857.  
  1858.         case WM_ACTIVATE:
  1859.             if (!wParam) {  /* app. is being de-activated */
  1860.                 if (win_systempaletteused)
  1861.                     win_stop_cycling();
  1862.                 break;
  1863.                 }
  1864.         case WM_QUERYNEWPALETTE:
  1865.             /* If palette realization causes a palette change,
  1866.              * we need to do a full redraw.
  1867.              */
  1868.              if (last_written_y >= 0) {
  1869.                  hDC = GetDC (hWnd);
  1870.                  SelectPalette (hDC, hPal, 0);
  1871.                  i = RealizePalette(hDC);
  1872.                  ReleaseDC (hWnd, hDC);
  1873.                  if (i) {
  1874.                      InvalidateRect (hWnd, (LPRECT) (NULL), 1);
  1875.                      return 1;
  1876.                      }
  1877.                  else
  1878.                      return FALSE;
  1879.                  }
  1880.              else
  1881.                  return FALSE;
  1882.  
  1883.         case WM_PALETTECHANGED:
  1884.             if (wParam != hWnd){
  1885.                 if (last_written_y >= 0) {
  1886.                     hDC = GetDC (hWnd);
  1887.                     SelectPalette (hDC, hPal, 0);
  1888.                     i = RealizePalette (hDC);
  1889.                     if (i)
  1890.                         UpdateColors (hDC);
  1891.                     else
  1892.                         InvalidateRect (hWnd, (LPRECT) (NULL), 1);
  1893.                     ReleaseDC (hWnd, hDC);
  1894.                     }
  1895.                 }
  1896.             break;
  1897.  
  1898.         default:
  1899.             return (DefWindowProc(hWnd, message, wParam, lParam));
  1900.     }
  1901.     return (NULL);
  1902. }
  1903.  
  1904. win_title_text(char *title)
  1905. {
  1906. char newtitle[80];
  1907.  
  1908. lstrcpy(newtitle, winfract_title_text);
  1909. lstrcat(newtitle,title);
  1910. SetWindowText(hMainWnd, newtitle);
  1911.  
  1912. }
  1913.  
  1914. win_oktocycle()
  1915. {
  1916. if (!(iRasterCaps) || iNumColors < 16) {
  1917.     stopmsg(0,
  1918.         winfract_msg96
  1919.          );
  1920.     return(0);
  1921.     }
  1922. return(1);
  1923. }
  1924.  
  1925. extern int win_animate_flag;
  1926.  
  1927. win_stop_cycling()
  1928. {
  1929. HDC hDC;                      /* handle to device context           */
  1930.  
  1931. hDC = GetDC(GetFocus());
  1932. SetSystemPaletteUse(hDC,SYSPAL_STATIC);
  1933. ReleaseDC(GetFocus(),hDC);
  1934.  
  1935. time_to_cycle = 0;
  1936. win_animate_flag = 0;
  1937. restoredac();
  1938. win_systempaletteused = FALSE;
  1939. SetSysColors(COLOR_ENDCOLORS,(LPINT)win_syscolorindex,(LONG FAR *)win_syscolorold);
  1940. return(0);
  1941. }
  1942.  
  1943. win_kill_all_zooming()
  1944. {
  1945.     if(Zooming)
  1946.         CancelZoom();
  1947.     else if(bMove)
  1948.         {
  1949.          extern POINT Center;
  1950.  
  1951.          EndSelection(Center, &Rect);
  1952.          ClearSelection(hWndCopy, &Rect, Shape);
  1953.          bMove = bMoving = bTrack = FALSE;
  1954.          }
  1955. }
  1956.  
  1957. void mono_dib_palette()
  1958. {
  1959. int i;        /* fill in the palette index values */
  1960.     for (i = 0; i < 128; i = i+2) {
  1961.         pDibInfo->bmiColors[i  ].rgbBlue      =   0;
  1962.         pDibInfo->bmiColors[i  ].rgbGreen     =   0;
  1963.         pDibInfo->bmiColors[i  ].rgbRed       =   0;
  1964.         pDibInfo->bmiColors[i  ].rgbReserved  =   0;
  1965.         pDibInfo->bmiColors[i+1].rgbBlue      = 255;
  1966.         pDibInfo->bmiColors[i+1].rgbGreen     = 255;
  1967.         pDibInfo->bmiColors[i+1].rgbRed       = 255;
  1968.         pDibInfo->bmiColors[i+1].rgbReserved  =   0;
  1969.         }
  1970. }
  1971.  
  1972. default_dib_palette()
  1973. {
  1974. int i, k;        /* fill in the palette index values */
  1975. int far *palette_values;    /* pointer to palette values */
  1976.  
  1977.     palette_values = (int far *)&pDibInfo->bmiColors[0];
  1978.     k = 0;
  1979.     for (i = 0; i < 256; i++) {
  1980.         palette_values[i] = k;
  1981.         if (++k >= iNumColors)
  1982.            if (iNumColors > 0)
  1983.                k = 0;
  1984.         }
  1985.     return(0);
  1986. }
  1987.  
  1988. rgb_dib_palette()
  1989. {
  1990. int i;        /* fill in the palette index values */
  1991.  
  1992.     for (i = 0; i < 256; i++) {
  1993.         pDibInfo->bmiColors[i].rgbRed       = dacbox[i][0] << 2;
  1994.         pDibInfo->bmiColors[i].rgbGreen     = dacbox[i][1] << 2;
  1995.         pDibInfo->bmiColors[i].rgbBlue      = dacbox[i][2] << 2;
  1996.         pDibInfo->bmiColors[i].rgbReserved  =   0;
  1997.         }
  1998.     return(0);
  1999. }
  2000.  
  2001. extern char win_funnyglasses_map_name[];
  2002.  
  2003. check_funnyglasses_name()
  2004. {
  2005.     if (win_funnyglasses_map_name[0] != 0) {
  2006.         if (ValidateLuts(win_funnyglasses_map_name) == 0) {
  2007.             win_savedac();
  2008.             }
  2009.         else {
  2010.             char temp[80];
  2011.             sprintf(temp,"Can't find map file: %s",
  2012.                 win_funnyglasses_map_name);
  2013.             stopmsg(0,temp);
  2014.             }
  2015.         }
  2016. }
  2017.  
  2018. /****************************************************************************
  2019.  
  2020.    FUNCTION:   MakeHelpPathName
  2021.  
  2022.    PURPOSE:    Winfract assumes that the .HLP help file is in the same
  2023.                directory as the Winfract executable.This function derives
  2024.                the full path name of the help file from the path of the
  2025.                executable.
  2026.  
  2027. ****************************************************************************/
  2028.  
  2029. void MakeHelpPathName(szFileName)
  2030. char * szFileName;
  2031. {
  2032.    char *  pcFileName;
  2033.    int     nFileNameLen;
  2034.  
  2035.    nFileNameLen = GetModuleFileName(hInst,szFileName,EXE_NAME_MAX_SIZE);
  2036.    pcFileName = szFileName + nFileNameLen;
  2037.  
  2038.    while (pcFileName > szFileName) {
  2039.        if (*pcFileName == '\\' || *pcFileName == ':') {
  2040.            *(++pcFileName) = '\0';
  2041.            break;
  2042.        }
  2043.    nFileNameLen--;
  2044.    pcFileName--;
  2045.    }
  2046.  
  2047.    if ((nFileNameLen+13) < EXE_NAME_MAX_SIZE) {
  2048.        lstrcat(szFileName, "winfract.hlp");
  2049.    }
  2050.  
  2051.    else {
  2052.        lstrcat(szFileName, "?");
  2053.    }
  2054.  
  2055.    return;
  2056. }
  2057.  
  2058. set_win_offset()
  2059. {
  2060. win_xoffset = ((long)xposition*((long)xdots-(long)xpagesize))/100L;
  2061. win_yoffset = ((long)yposition*((long)ydots-(long)ypagesize))/100L;
  2062. if (win_xoffset+xpagesize > xdots) win_xoffset = xdots-xpagesize;
  2063. if (win_yoffset+ypagesize > ydots) win_yoffset = ydots-ypagesize;
  2064. if (xpagesize >= xdots) win_xoffset = 0;
  2065. if (ypagesize >= ydots) win_yoffset = 0;
  2066. return(0);
  2067. }
  2068.  
  2069. win_savedac()
  2070. {
  2071.     memcpy(olddacbox,dacbox,256*3); /* save the DAC */
  2072.     colorpreloaded = 1;             /* indicate it needs to be restored */
  2073.  
  2074. }
  2075.  
  2076. /*
  2077.   Read a formula file, picking off the formula names.
  2078.   Formulas use the format "  name = { ... }  name = { ... } "
  2079. */
  2080.  
  2081. int get_formula_names()     /* get the fractal formula names */
  2082. {
  2083.    int numformulas, i;
  2084.    FILE *File;
  2085.    char msg[81], tempstring[201];
  2086.  
  2087.    FormName[0] = 0;        /* start by declaring failure */
  2088.    for (i = 0; i < MaxFormNameChoices; i++) {
  2089.       FormNameChoices[i][0] = 0;
  2090.       win_choices[i] = FormNameChoices[i];
  2091.       }
  2092.  
  2093.    if((File = fopen(FormFileName, "rt")) == NULL) {
  2094.       sprintf("I Can't find %s", FormFileName);
  2095.       stopmsg(1,msg);
  2096.       return(-1);
  2097.    }
  2098.  
  2099.    numformulas = 0;
  2100.    while(fscanf(File, " %20[^ \n\t({]", FormNameChoices[numformulas]) != EOF) {
  2101.       int c;
  2102.  
  2103.       while(c = getc(File)) {
  2104.      if(c == EOF || c == '{' || c == '\n')
  2105.         break;
  2106.       }
  2107.       if(c == EOF)
  2108.      break;
  2109.       else if(c != '\n'){
  2110.      numformulas++;
  2111.      if (numformulas >= MaxFormNameChoices) break;
  2112. skipcomments:
  2113.      if(fscanf(File, "%200[^}]", tempstring) == EOF) break;
  2114.      if (getc(File) != '}') goto skipcomments;
  2115.      if (stricmp(FormNameChoices[numformulas-1],"") == 0 ||
  2116.          stricmp(FormNameChoices[numformulas-1],"comment") == 0)
  2117.          numformulas--;
  2118.       }
  2119.    }
  2120.    fclose(File);
  2121.    win_numchoices = numformulas;
  2122.    qsort(FormNameChoices,win_numchoices,25,
  2123.          (int(*)(const void*, const void *))strcmp);
  2124.    return(0);
  2125. }
  2126.  
  2127. int parse_formula_names()     /* parse a fractal formula name */
  2128. {
  2129.  
  2130.    lstrcpy(FormName, win_choices[win_choicemade]);
  2131.  
  2132.    if (RunForm(FormName)) {
  2133.        FormName[0] = 0;     /* declare failure */
  2134.        stopmsg(0,"Can't Parse that Formula");
  2135.        return(0);
  2136.        }
  2137.  
  2138. return(1);
  2139. }
  2140.  
  2141. /* --------------------------------------------------------------------- */
  2142.  
  2143. get_lsys_name()        /* get the Lsystem formula name */
  2144. {
  2145.    int numentries, i;
  2146.    FILE *File;
  2147.    char buf[201];
  2148.    long point;
  2149.    long file_offset,name_offset;
  2150.  
  2151.    for (i = 0; i < MaxFormNameChoices; i++) {
  2152.       FormNameChoices[i][0] = 0;
  2153.       win_choices[i] = FormNameChoices[i];
  2154.       }
  2155.  
  2156.    if ((File = fopen(LFileName, "rb")) == NULL) {
  2157.       sprintf(buf,"I Can't find %s", LFileName);
  2158.       stopmsg(1,buf);
  2159.       LName[0] = 0;
  2160.       return(-1);
  2161.       }
  2162.  
  2163.    numentries = 0;
  2164.    file_offset = -1;
  2165.    while (1) {
  2166.       int c,len;
  2167.       do {
  2168.      ++file_offset;
  2169.      c = getc(File);
  2170.      } while (c == ' ' /* skip white space */
  2171.            || c == '\t' || c == '\n' || c == '\r');
  2172.       if (c == ';') {
  2173.      do {
  2174.         ++file_offset;
  2175.         c = getc(File);
  2176.         } while (c != '\n' && c != EOF && c != '\x1a');
  2177.      if (c == EOF || c == '\x1a') break;
  2178.      continue;
  2179.      }
  2180.       name_offset = file_offset;
  2181.       len = 0; /* next equiv roughly to fscanf(..,"%40[^ \n\r\t({\x1a]",buf) */
  2182.       while (c != ' ' && c != '\t' && c != '('
  2183.     && c != '{' && c != '\n' && c != '\r' && c != EOF && c != '\x1a') {
  2184.      if (len < 40) buf[len++] = c;
  2185.      c = getc(File);
  2186.      ++file_offset;
  2187.      }
  2188.       buf[len] = 0;
  2189.       while (c != '{' && c != '\n' && c != '\r' && c != EOF && c != '\x1a') {
  2190.      c = getc(File);
  2191.      ++file_offset;
  2192.      }
  2193.       if (c == '{') {
  2194.      while (c != '}' && c != EOF && c != '\x1a') {
  2195.         c = getc(File);
  2196.         ++file_offset;
  2197.         }
  2198.      if (c != '}') break;
  2199.      buf[ITEMNAMELEN] = 0;
  2200.      if (buf[0] != 0 && stricmp(buf,"comment") != 0) {
  2201.         lstrcpy(FormNameChoices[numentries],buf);
  2202.         memcpy((char *)&FormNameChoices[numentries][21],
  2203.             (char *)&name_offset,4);
  2204.         if (++numentries >= MaxFormNameChoices) {
  2205.            sprintf(buf,"Too many entries in file, first %d used",
  2206.                MaxFormNameChoices);
  2207.            stopmsg(0,buf);
  2208.            break;
  2209.            }
  2210.         }
  2211.      }
  2212.       else
  2213.      if (c == EOF || c == '\x1a') break;
  2214.       }
  2215.    fclose(File);
  2216.  
  2217.    win_numchoices = numentries;
  2218.    qsort(FormNameChoices,win_numchoices,25,
  2219.          (int(*)(const void *, const void *))strcmp);
  2220.    return(0);
  2221. }
  2222.  
  2223. cant_clip()
  2224. {
  2225. MessageBox (
  2226.    GetFocus(),
  2227.    winfract_msg99,
  2228.    winfract_msg01,
  2229.     MB_ICONSTOP | MB_OK);
  2230.     return(TRUE);
  2231. }
  2232.